﻿using System;
using System.Windows;
using System.Windows.Controls;

using Hetymine.Executioner.Data;
using Hetymine.Executioner.Triggers;

namespace Hetymine.Executioner.Plugins.Triggers.HotKey {
    /// <summary>
    /// Interaction logic for HotKeyTriggerConfigurator.xaml
    /// </summary>
    public partial class HotKeyTriggerConfigurator : UserControl, IConfigurator<ITrigger> {
        private HotKeyTrigger _Trigger;
        private bool _IsApply = true;

        public HotKeyTriggerConfigurator() {
            InitializeComponent();

            this.cHotKey.TextChanged += new TextChangedEventHandler(HotKey_TextChanged);
            this.cSelected.Click += new RoutedEventHandler(Selected_Click);
        }

        #region Control Events
        private void HotKey_TextChanged(object sender, TextChangedEventArgs e) {
            if (!this._IsApply) { return; }

            this._Trigger.HotKey = this.cHotKey.Text;
        }
        private void Selected_Click(object sender, RoutedEventArgs e) {
            if (!this._IsApply) { return; }

            this._Trigger.IsSelected = this.cSelected.IsChecked.Value;
        }
        #endregion

        #region IConfigurator<ITrigger> Members
        public void InitializeConfig(ITrigger config) {
            this._Trigger = config as HotKeyTrigger;

            this._IsApply = false;

            this.cHotKey.Text = this._Trigger.HotKey;
            this.cSelected.IsChecked = false;

            this._IsApply = true;
        }
        public UserControl ConfigPanel { get { return this; } }
        #endregion
    }
}
